//
//  WordDetailViewController.m
//  Learn
//
//  Created by apple on 2024/4/4.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "WordDetailViewController.h"
#import "BeiDanCiRequest.h"

@interface WordDetailViewController ()
/* <#描述#> */
@property (nonatomic, strong) UIButton    * bottonBtn;
@property (nonatomic, strong) UIButton    * voiceBtn;

@property (nonatomic, strong) UILabel    * wordLabel;
@property (nonatomic, strong) UILabel    * yinbiaoLabel;
@property (nonatomic, strong) UILabel    * expLabel;

@property (nonatomic, strong) UIImageView    * logoImg;

@property (nonatomic, strong) UIView    * tipView;
@property (nonatomic, strong) UILabel    * lijuLabel;
@property (nonatomic, strong) UILabel    * lijuEnLabel;
@property (nonatomic, strong) UILabel    * lijuZhLabel;

/* <#描述#> */
@property (nonatomic, strong) WordModel    * model;

@end

@implementation WordDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColor.whiteColor;
  
    self.title = @"开始背单词";

    [self initUI];
    [self getRequestData];
}
- (void)initUI {
    [self.view addSubview:self.voiceBtn];
    [self.view addSubview:self.bottonBtn];
    
    [self.view addSubview:self.wordLabel];
    [self.view addSubview:self.yinbiaoLabel];
    [self.view addSubview:self.expLabel];
    
    [self.view addSubview:self.logoImg];
    [self.view addSubview:self.tipView];
    [self.view addSubview:self.lijuLabel];
    [self.view addSubview:self.lijuEnLabel];
    [self.view addSubview:self.lijuZhLabel];
    
}
- (UILabel *)lijuZhLabel {
    if(!_lijuZhLabel){
        _lijuZhLabel = [[UILabel alloc]initWithFrame:CGRectMake(28, self.lijuEnLabel.bottom + 5, SCREEN_W - 56, 22)];
//        _lijuZhLabel.text = @"我是两天前来这儿的";
        _lijuZhLabel.textColor = COLOR_BLACK;
        _lijuZhLabel.font = PingFangMediumFont(16);
        _lijuZhLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _lijuZhLabel;
}
- (UILabel *)lijuEnLabel {
    if(!_lijuEnLabel){
        _lijuEnLabel = [[UILabel alloc]initWithFrame:CGRectMake(28, self.lijuLabel.bottom + 10, SCREEN_W - 56, 22)];
//        _lijuEnLabel.text = @"I came here two days ago..";
        _lijuEnLabel.textColor = COLOR_BLACK;
        _lijuEnLabel.font = PingFangMediumFont(16);
        _lijuEnLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _lijuEnLabel;
}
- (UILabel *)lijuLabel {
    if(!_lijuLabel){
        _lijuLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.tipView.right + 9, self.tipView.top - 2, 100, 22)];
        _lijuLabel.text = @"例句";
        _lijuLabel.textColor = COLOR_NOT_SELECT;
        _lijuLabel.font = PingFangMediumFont(16);
        _lijuLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _lijuLabel;
}
- (UIView *)tipView {
    if(!_tipView){
        _tipView = [[UIView alloc]initWithFrame:CGRectMake(self.logoImg.left
                                                           , self.logoImg.bottom + 19, 4, 14 )];
        
        _tipView.backgroundColor = COLOR_TOPIC_SELECT;
    }
    return _tipView;
}

- (UIImageView *)logoImg {
    if(!_logoImg){
        _logoImg = [[UIImageView alloc]initWithFrame:CGRectMake(28, 30 + self.expLabel.bottom, SCREEN_W - 56,0.56 *(SCREEN_W - 56))];
        _logoImg.contentMode = UIViewContentModeScaleAspectFill;
        [_logoImg js_setRoundedCorners:UIRectCornerAllCorners radii:10];
//        _logoImg.image = [UIImage imageNamed:@"planBg"];
    }
    return _logoImg;
}

- (UILabel *)expLabel {
    if(!_expLabel){
        _expLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 15 + self.yinbiaoLabel.bottom, SCREEN_W, 25)];
//        _expLabel.text = @"adv.以前";
        _expLabel.textColor = COLOR_NOT_SELECT;
        _expLabel.font = PingFangMediumFont(18);
        _expLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _expLabel;
}
- (UILabel *)yinbiaoLabel {
    if(!_yinbiaoLabel){
        _yinbiaoLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10 + self.wordLabel.bottom, SCREEN_W, 25)];
//        _yinbiaoLabel.text = @"[a'gau]";
        _yinbiaoLabel.textColor = COLOR_NOT_SELECT;
        _yinbiaoLabel.font = PingFangMediumFont(18);
        _yinbiaoLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _yinbiaoLabel;
}
- (UILabel *)wordLabel {
    if(!_wordLabel){
        _wordLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 30 + NavigationBarHeight, SCREEN_W, 45)];
//        _wordLabel.text = @"ago";
        _wordLabel.textColor = COLOR_BLACK;
        _wordLabel.font = PingFangMediumFont(32);
        _wordLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _wordLabel;
}

- (UIButton *)voiceBtn {
    if(!_voiceBtn){
        _voiceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _voiceBtn.frame = CGRectMake(SCREEN_W - 40, NavigationBarHeight, 40, 40);
        
        [_voiceBtn setImage:[UIImage imageNamed:@"voiceIcon"] forState:UIControlStateNormal];
        [_voiceBtn addTarget:self action:@selector(voiceBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _voiceBtn;
}

#pragma mark   播放
- (void)voiceBtnClicked:(UIButton *)sender {
    
}

- (UIButton *)bottonBtn {
    if(!_bottonBtn){
        _bottonBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _bottonBtn.frame = CGRectMake(10, SCREEN_H - SafeAreaBottomHeight - 55, SCREEN_W - 20, 45);
        if (self.isFromList) {
            [_bottonBtn setTitle:@"返回" forState:UIControlStateNormal];
        }else{
            [_bottonBtn setTitle:@"继续做题" forState:UIControlStateNormal];
        }
        
        [_bottonBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        _bottonBtn.titleLabel.font  = PingFangMediumFont(18);
        _bottonBtn.az_colors = @[(__bridge id)rgbHex(0x02A1F9, 1).CGColor,(__bridge id)rgbHex(0x29F19C,1).CGColor];
        _bottonBtn.az_startPoint = CGPointMake(0, 0.5);
        _bottonBtn.az_endPoint = CGPointMake(1, 0.5);
        [_bottonBtn js_setRoundedCorners:UIRectCornerAllCorners radii:22.5];
        [_bottonBtn addTarget:self action:@selector(bottonBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _bottonBtn;
}

#pragma mark   底部按钮点击
- (void)bottonBtnClicked:(UIButton *)sender {
    if (self.isFromList) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}


- (void)getRequestData{
    WS(WeakSelf)
    [BeiDanCiRequest request_getWordInfoWithId:self.wordId reslut:^(WordModel * _Nonnull model, BOOL isRequest) {
        if (isRequest) {
            [WeakSelf updateUIWithModel:model];
        }
    }];
}
- (void)updateUIWithModel:(WordModel*)model {
    self.model = model;
    self.wordLabel.text = model.words;
    self.yinbiaoLabel.text = [NSString stringWithFormat:@"[%@]",model.symbol];
    self.expLabel.text = model.pretations;
    [self.logoImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",model.wordPic]]];
    
    self.tipView.hidden = self.lijuLabel.hidden = self.lijuEnLabel.hidden = self.lijuZhLabel.hidden = YES;
    
}

@end
